<template>
  <div>
    <input type="text" v-model="username" /><br />
    <input type="password" v-model="password" /><br />
    <button @click="loginHandle">Submit</button>
  </div>
</template>

<script>
import http from '@/http'
export default {
  data() {
    return {
      username: '',
      password: '123456',
    }
  },
  methods: {
    async loginHandle() {
      try {
        const r = await http({
          url: '/login',
          method: 'post',
          data: {
            username: this.username,
            password: this.password,
          },
        })
        localStorage.setItem('token', r.headers.authorization)
        localStorage.setItem('user', JSON.stringify(r.data.data))
        this.$router.push('/')
      } catch (e) {
        console.log(e.response.status)
      }
    },
  },
}
</script>
